import SwiftUI
import SPGlassKit

public struct GlassSliderExample: GlassExample {
    public static let componentID = "glass-slider"
    @State private var brightness = 0.6
    @State private var temperature = 21.0
    @State private var budget = 1500.0
    @State private var locked = 0.3
    @State private var isDragging = false

    public init() {}

    public var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 24) {
                GlassSlider("Brightness", value: $brightness, format: .percent.precision(.fractionLength(0)))

                GlassSlider("Temperature", value: $temperature, in: 16...28, step: 0.5, showsBoundLabels: true) { value in
                    Measurement(value: value, unit: UnitTemperature.celsius)
                        .formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number.precision(.fractionLength(1))))
                }

                GlassSlider(
                    "Monthly budget",
                    value: $budget,
                    in: 0...5000,
                    step: 250,
                    format: .currency(code: "CAD").precision(.fractionLength(0)),
                    onEditingChanged: { isDragging = $0 }
                )
                Text(isDragging ? "Adjusting…" : "Released")
                    .font(.caption)
                    .foregroundStyle(.secondary)

                GlassSlider("Locked by policy", value: $locked)
                    .disabled(true)
            }
            .padding()
        }
    }
}

#Preview("GlassSlider") { GlassSliderExample().glassTheme(.ocean) }
